<div class="page" id="forum">
	<?php if($this->view->func == 'index') { ?>
		<h3>Forum</h3>
		<table>
			<?php if(count($this->view->data) > 0) { ?>
				<?php foreach($this->view->data as $idx => $one) { ?>
					<tr>
						<td class="ico"><img src="/img/<?php echo $one['read'] ? 'read' : 'unread'; ?>.png" width="24" height="24" alt="<?php echo $one['read'] ? 'Read' : 'Unread'; ?>" /></td>
						<td class="cat">
							<h4><a href="forum/category/<?php echo $one['link']; ?>" data-to="ajax"><?php echo $one['name']; ?></a></h4>
							<span><?php echo $one['description']; ?></span>
						</td>
						<td class="count"><?php echo ($one['topics'] . ($one['topics'] == 1 ? ' Topic' : ' Topics')) . ', ' . ($one['posts'] . ($one['posts'] == 1 ? ' Post' : ' Posts')); ?></td>
						<td class="last_topic">
							<?php echo $this->partial('helpers/avatar.php', array(
								'size' => 30,
								'user' => array(
									'id' => $one['last_user'],
									'link' => $one['last_ulink'],
									'name' => $one['last_uname'],
									'avatar' => $one['last_avatar']
								)
							)); ?>
							<div class="info">
								<?php if($one['last_name']) { ?>
									<a href="forum/topic/<?php echo $one['last_link']; ?>" data-to="ajax" title="<?php echo $one['last_name']; ?>"><?php echo $one['last_name']; ?></a>
									<span><?php echo $this->partial('helpers/time.php', array('time' => $one['last_time'])); ?></span>
								<?php } else { ?>
									<span class="nda">No data available.</span>
								<?php } ?>
							</div>
							<div class="clear"></div>
						</td>
					</tr>
					<?php if(count($this->view->data) != $idx + 1) { ?>
						<tr><td colspan="4" class="delimiter"></td></tr>
					<?php } ?>
				<?php } ?>
			<?php } else { ?>
				<tr><td>No forum categories defined.</td></tr>
			<?php } ?>
		</table>
	<?php } elseif($this->view->func == 'category') { ?>
		<h3><a href="forum" data-to="ajax">Forum</a> / <?php echo $this->view->category['name']; ?></h3>
		<table>
			<?php if(count($this->view->data) > 0) { ?>
				<tr>
					<td colspan="4">
						<?php if($this->view->permission) { ?>
							<form class="new_topic">
								<div class="left"><button type="submit">New Topic</button></div>
								<div class="right">
									<?php echo $this->partial('helpers/pagination.php', array('url' => "forum/category/{$this->view->category['link']}", 'pagination' => $this->view->pagination)); ?>
									<div class="clear"></div>
								</div>
								<div class="clear"></div>
							</form>
						<?php } else { ?>
							<div class="left">
								<?php echo $this->partial('helpers/pagination.php', array('url' => "forum/category/{$this->view->category['link']}", 'pagination' => $this->view->pagination)); ?>
								<div class="clear"></div>
							</div>
							<div class="clear"></div>
						<?php } ?>
					</td>
				</tr>
				<tr><td colspan="4" class="delimiter"></td></tr>
				<?php foreach($this->view->data as $idx => $one) { ?>
					<tr>
						<td class="ico"><img src="/img/<?php echo $one['read'] ? 'read' : 'unread'; ?>.png" width="24" height="24" alt="<?php echo $one['read'] ? 'Read' : 'Unread'; ?>" /></td>
						<td class="cat">
							<div>
								<h4><a href="forum/topic/<?php echo $one['link']; ?>" data-to="ajax" title="<?php echo $one['name']; ?>"><?php echo $one['name']; ?></a></h4>
								<span>
									By: <a data-to="ajax" href="profile/view/<?php echo $one['author_link']; ?>"><?php echo $one['author_name']; ?></a>
									<?php echo $one['sticky'] == 1 ? '<span class="bull">&bull;</span> Sticky' : ''; ?>
									<?php echo $one['locked'] == 1 ? '<span class="bull">&bull;</span> Locked' : ''; ?>
									<?php echo $one['type'] == 1 ? '<span class="bull">&bull;</span> Accepted' : ''; ?>
									<?php echo $one['type'] == 2 ? '<span class="bull">&bull;</span> Declined' : ''; ?>
								</span>
							</div>
						</td>
						<td class="count"><?php echo ($one['replies'] . ($one['replies'] == 1 ? ' Reply' : ' Replies')) . ', ' . ($one['views'] . ($one['views'] == 1 ? ' View' : ' Views')); ?></td>
						<td class="last_post">
							<?php echo $this->partial('helpers/avatar.php', array(
								'size' => 30,
								'user' => array(
									'id' => $one['last_user'],
									'link' => $one['last_link'],
									'name' => $one['last_name'],
									'avatar' => $one['last_avatar']
								)
							)); ?>
							<div class="info">
								<a data-to="ajax" href="profile/view/<?php echo $one['last_link']; ?>"><?php echo $one['last_name']; ?></a>
								<span><?php echo $this->partial('helpers/time.php', array('time' => $one['last_time'])); ?></span>
							</div>
							<div class="clear"></div>
						</td>
					</tr>
					<tr><td colspan="4" class="<?php echo $this->view->last_sticky && $this->view->last_sticky == $one['id'] ? "separator" : "delimiter"; ?>"></td></tr>
				<?php } ?>
				<tr>
					<td colspan="4">
						<?php if($this->view->permission) { ?>
							<form class="new_topic">
								<div class="left"><button type="submit">New Topic</button></div>
								<div class="right">
									<?php echo $this->partial('helpers/pagination.php', array('url' => "forum/category/{$this->view->category['link']}", 'pagination' => $this->view->pagination)); ?>
									<div class="clear"></div>
								</div>
								<div class="clear"></div>
							</form>
						<?php } else { ?>
							<div class="right">
								<?php echo $this->partial('helpers/pagination.php', array('url' => "forum/category/{$this->view->category['link']}", 'pagination' => $this->view->pagination)); ?>
								<div class="clear"></div>
							</div>
							<div class="clear"></div>
						<?php } ?>
					</td>
				</tr>
			<?php } else { ?>
				<?php if($this->view->permission) { ?>
					<tr><td colspan="4">
						<form class="new_topic">
							<div class="left"><button type="submit">New Topic</button></div>
							<div class="clear"></div>
						</form>
					</td></tr>
					<tr><td colspan="4" class="delimiter"></td></tr>
				<?php } ?>
				<tr><td colspan="4">No topics found.</td></tr>
			<?php } ?>
		</table>
	<?php } elseif($this->view->func == 'post') { ?>
		<h3><a href="forum" data-to="ajax">Forum</a> / <a href="forum/category/<?php echo $this->view->category['link']; ?>" data-to="ajax"><?php echo $this->view->category['name']; ?></a> / New Topic</h3>
		<table>
			<tr>
				<td class="author">
					<?php echo $this->partial('helpers/avatar.php', array(
						'size' => 40,
						'user' => array(
							'id' => $this->session->auth['id'],
							'link' => $this->session->auth['link'],
							'name' => $this->session->auth['name'],
							'avatar' => $this->session->auth['avatar']
						)
					)); ?>
					<div class="clear"></div>
				</td>
				<td class="reply">
					<form id="form_topic">
						<label class="input">
							<input type="text" value="" name="title" maxlength="50">
							<span>Title</span>
						</label>
						<label class="textarea">
							<textarea name="message"></textarea>
							<span>Message</span>
						</label>
						<div class="left bbcode">
							<a data-handle="b" href="javascript:void(0);">b</a>
							<span class="bull">&bull;</span>
							<a data-handle="i" href="javascript:void(0);">i</a>
							<span class="bull">&bull;</span>
							<a data-handle="u" href="javascript:void(0);">u</a>
							<span class="bull">&bull;</span>
							<a data-handle="url" href="javascript:void(0);">url</a>
							<span class="bull">&bull;</span>
							<a data-handle="img" href="javascript:void(0);">img</a>
							<span class="bull">&bull;</span>
							<a data-handle="quote" href="javascript:void(0);">quote</a>
						</div>
						<div class="right"><button type="submit" data-id="<?php echo $this->view->category['id']; ?>">Post</button></div>
						<div class="clear"></div>
					</form>
					<div class="clear"></div>
				</td>
			</tr>
		</table>
	<?php } elseif($this->view->func == 'topic') { ?>
		<h3><a href="forum" data-to="ajax">Forum</a> / <a href="forum/category/<?php echo $this->view->topic['category_link']; ?>" data-to="ajax"><?php echo $this->view->topic['category_name']; ?></a> / <?php echo $this->view->topic['name']; ?></h3>
		<table>
			<tr>
				<td colspan="2">
					<?php if(($this->view->topic['locked'] == 1 && $this->view->permission) || ($this->view->topic['locked'] == 0 && isset($this->session->auth))) { ?>
						<form class="topic_handlers">
							<?php if($this->view->permission) { ?>
								<?php if($this->view->topic['category_type'] == 2) { ?>
									<div class="left"><button data-handle="reply">Reply</button>&nbsp;<?php if($this->view->topic['type'] != 1) { ?>&nbsp;<button data-id="<?php echo $this->view->topic['id']; ?>" data-handle="accept">Accept</button>&nbsp;<?php } ?><?php if($this->view->topic['type'] != 2) { ?>&nbsp;<button data-id="<?php echo $this->view->topic['id']; ?>" data-handle="decline">Decline</button><?php } ?></div>
								<?php } else { ?>
									<div class="left"><button data-handle="reply">Reply</button>&nbsp;&nbsp;<button data-id="<?php echo $this->view->topic['id']; ?>" data-handle="<?php echo $this->view->topic['sticky'] == 1 ? 'unstick' : 'stick'; ?>"><?php echo $this->view->topic['sticky'] == 1 ? 'Unstick' : 'Stick'; ?></button>&nbsp;&nbsp;<button data-id="<?php echo $this->view->topic['id']; ?>" data-handle="<?php echo $this->view->topic['locked'] == 1 ? 'open' : 'lock'; ?>"><?php echo $this->view->topic['locked'] == 1 ? 'Open' : 'Lock'; ?></button></div>
								<?php } ?>
							<?php } else { ?>
								<div class="left"><button data-handle="reply">Reply</button></div>
							<?php } ?>
							<div class="right">
								<?php echo $this->partial('helpers/pagination.php', array('url' => "forum/topic/{$this->view->topic['link']}", 'pagination' => $this->view->pagination)); ?>
								<div class="clear"></div>
							</div>
							<div class="clear"></div>
						</form>
					<?php } else { ?>
						<div class="left">
							<?php echo $this->partial('helpers/pagination.php', array('url' => "forum/topic/{$this->view->topic['link']}", 'pagination' => $this->view->pagination)); ?>
							<div class="clear"></div>
						</div>
						<div class="clear"></div>
					<?php } ?>
				</td>
			</tr>
			<tr><td colspan="2" class="delimiter"></td></tr>
			<?php foreach($this->view->data as $idx => $one) { ?>
				<tr id="reply_<?php echo $one['id']; ?>">
					<td class="author">
						<?php echo $this->partial('helpers/avatar.php', array(
							'size' => 40,
							'user' => array(
								'id' => $one['author_id'],
								'link' => $one['author_link'],
								'name' => $one['author_name'],
								'avatar' => $one['author_avatar']
							)
						)); ?>
						<div class="clear"></div>
					</td>
					<td class="reply">
						<div class="meta">
							<h4><a data-to="ajax" href="profile/view/<?php echo $one['author_link']; ?>"><?php echo $one['author_name']; ?></a></h4>
							<span><?php echo $one['author_rank']; ?> <span class="bull">&bull;</span> Posted: <?php echo $this->partial('helpers/time.php', array('time' => $one['time'])); ?>
								<?php if(($this->view->topic['locked'] == 1 && $this->view->permission) || ($this->view->topic['locked'] == 0 && isset($this->session->auth))) { ?>
									<?php if(isset($this->session->auth) && $this->session->auth['id'] != $one['author_id']) { ?>
										<span class="bull">&bull;</span> <a href="javascript:void(0);" class="reply_quote" data-id="<?php echo $one['id']; ?>">Quote</a>
									<?php } ?>
								<?php } if($this->view->permission || ($this->view->topic['locked'] == 0 && isset($this->session->auth) && $this->session->auth['id'] == $one['author_id'])) { ?>
									<span class="bull">&bull;</span> <a href="javascript:void(0);" class="reply_edit" data-id="<?php echo $one['id']; ?>">Edit</a>
								<?php } if($this->view->permission) { ?>
									<span class="bull">&bull;</span> <a href="javascript:void(0);" class="reply_delete" data-id="<?php echo $one['id']; ?>">Delete</a>
								<?php } ?>
							</span>
						</div>
						<div class="msg"><?php echo $one['message']; ?></div>
					</td>
				</tr>
				<tr><td colspan="2" class="delimiter"></td></tr>
			<?php } ?>
			<tr>
				<td colspan="2">
					<?php if(($this->view->topic['locked'] == 1 && $this->view->permission) || ($this->view->topic['locked'] == 0 && isset($this->session->auth))) { ?>
						<form class="topic_handlers">
							<?php if($this->view->permission) { ?>
								<?php if($this->view->topic['category_type'] == 2) { ?>
									<div class="left"><button data-handle="reply">Reply</button>&nbsp;<?php if($this->view->topic['type'] != 1) { ?>&nbsp;<button data-id="<?php echo $this->view->topic['id']; ?>" data-handle="accept">Accept</button>&nbsp;<?php } ?><?php if($this->view->topic['type'] != 2) { ?>&nbsp;<button data-id="<?php echo $this->view->topic['id']; ?>" data-handle="decline">Decline</button><?php } ?></div>
								<?php } else { ?>
									<div class="left"><button data-handle="reply">Reply</button>&nbsp;&nbsp;<button data-id="<?php echo $this->view->topic['id']; ?>" data-handle="<?php echo $this->view->topic['sticky'] == 1 ? 'unstick' : 'stick'; ?>"><?php echo $this->view->topic['sticky'] == 1 ? 'Unstick' : 'Stick'; ?></button>&nbsp;&nbsp;<button data-id="<?php echo $this->view->topic['id']; ?>" data-handle="<?php echo $this->view->topic['locked'] == 1 ? 'open' : 'lock'; ?>"><?php echo $this->view->topic['locked'] == 1 ? 'Open' : 'Lock'; ?></button></div>
								<?php } ?>
							<?php } else { ?>
								<div class="left"><button data-handle="reply">Reply</button></div>
							<?php } ?>
							<div class="right">
								<?php echo $this->partial('helpers/pagination.php', array('url' => "forum/topic/{$this->view->topic['link']}", 'pagination' => $this->view->pagination)); ?>
								<div class="clear"></div>
							</div>
							<div class="clear"></div>
						</form>
					<?php } else { ?>
						<div class="right">
							<?php echo $this->partial('helpers/pagination.php', array('url' => "forum/topic/{$this->view->topic['link']}", 'pagination' => $this->view->pagination)); ?>
							<div class="clear"></div>
						</div>
						<div class="clear"></div>
					<?php } ?>
				</td>
			</tr>
			<?php if(($this->view->topic['locked'] == 1 && $this->view->permission) || ($this->view->topic['locked'] == 0 && isset($this->session->auth))) { ?>
				<tr><td colspan="2" class="delimiter"></td></tr>
				<tr>
					<td class="author">
						<?php echo $this->partial('helpers/avatar.php', array(
							'size' => 40,
							'user' => array(
								'id' => $this->session->auth['id'],
								'link' => $this->session->auth['link'],
								'name' => $this->session->auth['name'],
								'avatar' => $this->session->auth['avatar']
							)
						)); ?>
						<div class="clear"></div>
					</td>
					<td class="reply">
						<form id="form_reply">
							<label class="textarea">
								<textarea name="message"></textarea>
								<span>Message</span>
							</label>
							<div class="left bbcode">
								<a data-handle="b" href="javascript:void(0);">b</a>
								<span class="bull">&bull;</span>
								<a data-handle="i" href="javascript:void(0);">i</a>
								<span class="bull">&bull;</span>
								<a data-handle="u" href="javascript:void(0);">u</a>
								<span class="bull">&bull;</span>
								<a data-handle="url" href="javascript:void(0);">url</a>
								<span class="bull">&bull;</span>
								<a data-handle="img" href="javascript:void(0);">img</a>
								<span class="bull">&bull;</span>
								<a data-handle="quote" href="javascript:void(0);">quote</a>
							</div>
							<div class="right"><button type="submit" data-id="<?php echo $this->view->topic['id']; ?>">Post</button></div>
							<div class="clear"></div>
						</form>
						<div class="clear"></div>
					</td>
				</tr>
			<?php } ?>
		</table>
	<?php } ?>
</div>